package com.fmsz.xmly.adapters.broadcast;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fmsz.xmly.R;
import com.fmsz.xmly.entitys.broadcast.province.RadioStationEntity;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/7.
 */

public class ProvinceLvAdapter extends BaseAdapter{

    private Context context;
    private List<RadioStationEntity.ResultEntity> list;

    public ProvinceLvAdapter(Context context) {
        this.context = context;
        this.list = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }
    public void addAll(Collection<? extends RadioStationEntity.ResultEntity> list){
        this.list.addAll(list);
        notifyDataSetChanged();
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.find_broad_lv_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(list.get(position).getRadioCoverSmall()).into(holder.icon);
        holder.tv1.setText(list.get(position).getRname());
        holder.tv2.setText("正在直播："+list.get(position).getProgramName());
        holder.tv3.setText(list.get(position).getRadioPlayCount());
        return convertView;
    }
    public static class ViewHolder{
        private ImageView icon;
        private TextView tv1;
        private TextView tv2;
        private TextView tv3;

        public ViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            icon = ((ImageView) convertView.findViewById(R.id.broad_lv_icon));
            tv1 = ((TextView) convertView.findViewById(R.id.broad_tv_top));
            tv2 = ((TextView) convertView.findViewById(R.id.broad_tv_mid));
            tv3 = ((TextView) convertView.findViewById(R.id.broad_tv_end));

        }
    }
}
